package com.example.cms2.Controller;

import com.example.cms2.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @return
 */
@Controller
public class RegisterController {
    @Autowired
    UserMapper userMapper;
    @GetMapping("/user/register")
    public String toRegisteruser(){
        return "register";
    }
    @PostMapping("/user/register")
    public String registerUser(String username, String password, Model model){
        if(userMapper.registerUser(username,password)!=0){
            model.addAttribute("msg","注册成功!");
            return "index";
        }
        else {
            model.addAttribute("msg","注册失败!!!");
            return "index";
        }

    }

}
